package com.pro.util.generator;

import java.util.List;

public abstract class BaseClassPro {
	public static String TAB = "\t";
	public static String SPACE = " ";
	public static String SPLIT = ";";
	public static String LEFT_K = "{";

	public static String RIGHT_K = "}";
	public static String PUBLIC = "public";

	private static String PRIVATE = "private";
	private String name;
	private String type;
	private String control;
	private String isMethod;
	public abstract boolean isMethod();
	public String returnType;
	private String defaultConvert(String type){
		type = type.toLowerCase();
		return FileUtil.getUpString(type);
	}
	private List<String> typeList;
	
	public List<String> getTypeList() {
		return typeList;
	}

	public void setTypeList(List<String> typeList) {
		this.typeList = typeList;
	}
	public String convertJdbcType(String type){
		String jdbcType = "VARCHAR";
		switch (type.toUpperCase()) {
		case "INT":
			jdbcType = "INTEGER";
			break;
		default:
			jdbcType = type.toUpperCase();
			break;
		}
		return jdbcType;
	}
	public String convertJavaType(String type){
		String javaType = "String";
		switch (type) {
		case "INTEGER":
		case "TINYINT":
			javaType = "Integer";
			break;
		case "DATETIME":
			javaType = "Date";
			break;
		case "VARCHAR":
		case "TEXT":
		case "Longblob":
			javaType = "String";
			break;
		default:
			javaType = defaultConvert(type);
			break;
		}
//		typeList.add(javaType);
		return javaType;
	}
	public String getJavaType(){
		return convertJavaType(this.getType());
	}
	
	public String getIsMethod() {
		return isMethod;
	}
	public void setIsMethod(String isMethod) {
		this.isMethod = isMethod;
	}
	public String getReturnType() {
		return returnType;
	}
	public void setReturnType(String returnType) {
		this.returnType = returnType;
	}
	public abstract String getName();
	
	public void setName(String name) {
		this.name = name;
	}
	public abstract String getType() ;
	public void setType(String type) {
		this.type = type;
	}
	public String getControl() {
		return control;
	}
	public void setControl(String control) {
		this.control = control;
	}
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		if(this.getControl()==null&&!this.isMethod()){
			sb.append(TAB+PRIVATE+SPACE+this.getType()+SPACE+this.getName()+SPLIT+"\r\n\t");
			generateGetMethod(sb);
			generateSetMethod(sb);
			
		}
		return sb.toString();
	}
	private void generateGetMethod(StringBuffer sb){
		sb.append(TAB+PUBLIC+SPACE+this.getType()+SPACE+"get"+FileUtil.getUpString(this.getName())+"()");
		sb.append(LEFT_K+"\r\n\t");
		sb.append("\t\t"+"return this."+this.getName()+SPLIT);
		sb.append("\r\n\t\t"+RIGHT_K+"\r\n\t");
	}
	private void generateSetMethod(StringBuffer sb){
		sb.append(TAB+PUBLIC+SPACE+"void"+SPACE+"set"+FileUtil.getUpString(this.getName())
				+"("+this.getType()+SPACE+this.getName()+")");
		sb.append(LEFT_K+"\r\n\t");
		sb.append("\t\t"+"this."+this.getName() +"=" +this.getName()+SPLIT);
		sb.append("\r\n\t\t"+RIGHT_K+"\r\n\t");
	}
}
